<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>留学生管理系统</title>  
        <link rel="stylesheet" href="${path}/css/admin2.css">
        <style>
            #college-modal-1, #college-modal-2{
                margin: 12% auto;
                padding: 10px;
                width: 400px;
            }
        </style>
        <script>
            var _current_item = "#admincolmanage";
        </script>
        <script type="text/javascript" src="${path}/js/jquery.min.js"></script>
    </head>
    <body>
        <!--header-->
        <div id="above-mask">
            <div class="fileupload pannel hide" id="fileupload-pannel">
                <div class="close-container">
                    <a class="close" onclick="hide('#above-mask, #mask, #fileupload-pannel');">×</a>
                </div>
                <form action="${path}/admincolmanage/fileUpload" method="post" enctype="multipart/form-data" name="fileForm">
                    <div style="margin-top: 30px;"> 上传文件：（支持Excel 97-2003 工作簿 .xls格式文件）</div>
                    <input id="fileCover" class="left" readonly="readonly" placeholder="导入excel文件" type="text" style="width: 280px; height: 22px;">
                    <button onclick="$('#uploadFile').click();return false;" style="background: #aaa">浏览文件</button>
                    <input type="file" name="uploadFile" required="required" id="uploadFile" style="display:none" onchange="$('#fileCover').val($(this).val());">
                    <div>
                        <button type="submit" style="display: block; margin: 0 auto;">提交</button> 
                    </div>
                </form>
            </div>
            <div class="pannel hide" id="college-modal-1">
                <div class="am-modal-dialog">
                    <div class="close-container">
                        <a class="close" onclick="hide('#mask, #above-mask, #college-modal-1')">&times;</a>
                    </div>
                    <form action="${path}/admincolmanage/submit" method="post">
                        <table class="table table-bordered">
                            <tr>
                                <td>学院名称</td>
                                <td><input type="text" placeholder="必填" name="college.collegeName" required="required"></td>
                            </tr>
                            <tr>
                                <td>学院编码</td>
                                <td><input type="text" placeholder="必填" name="college.collegeCode" required="required"></td>
                            </tr>
                            <tr><td colspan="2"><button type="submit">提交</button></td></tr>
                        </table>
                    </form>		
                </div>
            </div>
            <div class="pannel hide" id="college-modal-2">
                <div class="close-container">
                    <a class="close" onclick="hide('#mask, #above-mask, #college-modal-2')">&times;</a>
                </div>
                <table class="table table-bordered" id="collegetable2">
                    <tr>
                        <td>学院名称</td>
                        <td></td>
                    </tr>
                    <tr>
                        <td>学院编码</td>
                        <td><input type="text" id="collegeCode" name="college.collegeCode" placeholder="必填" value=""></td>
                    </tr>
                    <tr>
                        <td colspan="2">
                            <input type="hidden" id="id" name="college.id" value="">
                            <input type="hidden" id="collegeName" name="college.collegeName" value="">
                            <button type="button" onclick="ajaxupdate();$('#mask, #above-mask, #college-modal-2').hide();">确定</button>
                        </td>
                    </tr>
                </table>
            </div>
        </div>
        <div id="mask"></div>
        <div id="header"></div>
        <div id="main">
            <div id="side-menu"></div>
            <div id="container">
                <div id="inner-border">
                    <button onclick="window.location.href = '${path}/admincolmanage/fileDownload'">模板下载</button>
                    <button onclick="show('#mask, #above-mask, #fileupload-pannel')">批量导入</button>
                    <button onclick="window.location.href='${path}/acainfExport/exportExcel'">批量导出</button>
                    <button onclick="show('#mask, #above-mask, #college-modal-1')">新增学院</button>
                    <form action="${path}/admincolmanage/batch" >
                        <input type="hidden" name="checkboxValue" id="checkboxValue">
                        <div id="error" style="display:none">${error!}</div>
                        <table id="collegetable">
                            <thead>
                                <tr>
                                    <th>&nbsp;&nbsp;&nbsp;</th>
                                    <th>学院名称</th>
                                    <th>学院编码</th>
                                    <th style="display:none"></th>
                                    <th>操作</th>
                                </tr> 
                            </thead>
                            <tbody id="mtbody">
                                <#if college?exists>
                                <#list college as c> 
                                <tr>
                                    <td><input type="checkbox" value="${c.id}" name="colCheckbox" id="majCheckbox" ></td>
                                    <td name="majors">${c.collegeName}</td>
                                    <td name="majors">${c.collegeCode}</td>
                                    <td name="majors" style="display:none">${c.id}</td>
                                    <!-- onclick="window.location.href='${path}/adminmajmanage/edit/${c.id}'" -->
                                    <td> <button type="button" class="edit" name="editBtn" onclick="edit(this);$('#mask, #above-mask, #college-modal-2').show();return false;">编辑</button></td>
                                </tr>
                                </#list>
                                </#if>
                            </tbody>
                        </table>
                        <button class="delete" type="submit" onclick="getParam('collegetable', 'checkboxValue');">删除</button>
                    </form>
                </div>
                
            </div>
        </div>
        <div id="footer"></div>
        <script type="text/javascript" src="${path}/js/admin-main-appearance.js"></script>

        <!-- DataTables JavaScript -->
        <script src="${path}/bower_components/datatables/media/js/jquery.dataTables.min.js"></script>
        <script src="${path}/bower_components/datatables-plugins/api/fnGetHiddenNodes.js"></script>
        <script src="${path}/bower_components/datatables-plugins/api/fnGetTd.js"></script>
        <script src="${path}/bower_components/datatables-plugins/api/fnGetTds.js"></script>
        <script src="${path}/bower_components/datatables-plugins/api/fnGetColumnData.js"></script>
        <script src="${path}/bower_components/datatables-plugins/integration/bootstrap/3/dataTables.bootstrap.min.js"></script>
        <script src="${path}/js/linkPage.js"></script>

        <script type="text/javascript">
                            var row;
                            function edit(node) {
                                var tr1 = node.parentNode.parentNode;

                                document.getElementById('collegetable2').rows[0].cells[1].innerText = tr1.cells[1].innerText;
                                document.getElementById('collegeCode').value = tr1.cells[2].innerText;
                                document.getElementById('id').value = tr1.cells[0].children[0].value;
                                document.getElementById('collegeName').value = tr1.cells[1].innerText;
                                row = tr1.rowIndex;
                                return row;
                            }
                            function ajaxupdate() {
                                $.ajax({
                                    type: "post",
                                    url: '${path}/admincolmanage/ajaxupdate',
                                    data: {
                                        collegeCode: $('#collegeCode').val(),
                                        id: $('#id').val(),
                                        collegeName: $('#collegeName').val(),
                                    },
                                    datatype: "json",
                                    success: function (data) {
                                        document.getElementById('collegetable').rows[row].cells[2].innerText = data.college[0]["collegeCode"];
                                        alert(data.error);
                                    }

                                });
                            }
        </script>
        <script type="text/javascript">
            $(document).ready(function () {
                $('#collegetable').DataTable({
                    responsive: true,
                    ordering: false,
                    searching: true,
                    "bLengthChange": false,
                    "bRetrieve": true,
                    "bFilter": true//过滤功能
                });
            });
        </script>

        <script type="text/javascript">
            $(document).ready(function () {
                if ($("#error").html() != "") {
                    Alert($("#error").html());
                }
                //alert($("#error").html());}
            });
        </script> 
        <script>
            //自动关闭提示框  
            function Alert(str) {
                alert(str);
            }
        </script>
    </body>
</html>
